/*
 * Copyright 2010-2011 WebEqua Team
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.mathcloud.math.core.maple.operator.algebra;

//import classes slf4j
import org.mathcloud.math.core.maple.factory.MapleQuantityObjectFactory;
import org.mathcloud.math.core.maple.manager.MapleSupervisor;
import org.mathcloud.math.core.maple.operator.MapleNaryOperator;
import org.mathcloud.math.core.maple.quantity.MapleQuantityObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import classes org.mathcloud.math.core.common
import org.mathcloud.math.core.common.operator.algebra.Lcm;
import org.mathcloud.math.core.common.quantity.QuantityObject;
//import classes org.mathcloud.math.core.maple

public class MapleLcm extends MapleNaryOperator implements Lcm
{
	public MapleLcm()
	{
		super();
		signature.setMMLContentTag("lcm");
	}	
	
	@Override	
	public QuantityObject calculate(QuantityObject operand1, QuantityObject operand2)
	{
		try {
			MapleQuantityObject tOp1 = MapleQuantityObjectFactory.getInstance(operand1);
			MapleQuantityObject tOp2 = MapleQuantityObjectFactory.getInstance(operand2);
			String MapleJob = MapleQuantityObject.getEvaluateForm("map", new Object[] {"lcm["+tOp2.getVarName()+"]",tOp1.getVarName(),tOp2.getVarName()}) + "evalhf(%):";
			log.debug("Maple form is {}", MapleJob);	
			return MapleQuantityObjectFactory.getInstance(getResultSignature(tOp1,tOp2), MapleSupervisor.getMapleEngine().evaluate(MapleJob));
		} 
		catch (Exception e) {
			log.error("Exception:", e);
		}
		return null;
	}
	
	private static final Logger log = LoggerFactory.getLogger(MapleLcm.class);	
}
